# Contributor: Joseph Benden <joe@benden.us>
# Maintainer: Joseph Benden <joe@benden.us>
pkgname=stgit
pkgver=1.3
pkgrel=1
pkgdesc="Manage a stack of patches using GIT as a backend"
arch="noarch"
url="http://www.procode.org/stgit/"
license="GPL-2.0-or-later"
options="!check" # unit-tests fail due to iconv usage
depends="git python3"
makedepends="asciidoc xmlto perl py3-setuptools"
subpackages="
	$pkgname-doc
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-bash-completion
	$pkgname-vim:_vim:noarch
	$pkgname-emacs:_emacs:noarch
	"
source="https://github.com/stacked-git/stgit/releases/download/v$pkgver/stgit-$pkgver.tar.gz"

prepare() {
	default_prepare

	# this will be a noop, as we are working with a tarball,
	# but throws git errors --> just get rid of it
	echo "version=\"$pkgver\"" > stgit/builtin_version.py
}

check() {
	make \
		PYTHON=python3 \
		prefix=/usr \
		mandir=/usr/share/man/ \
			test
}

build() {
	make \
		PYTHON=python3 \
		prefix=/usr \
		mandir=/usr/share/man/ \
			all doc
}

package() {
	make \
		DESTDIR="$pkgdir" \
		PYTHON=python3 \
		prefix=/usr \
		mandir=/usr/share/man/ \
			install install-doc

	# shell completion
	rm -rf "$pkgdir"/usr/share/stgit/completions
	install -Dm0644 completion/stgit.bash \
		"$pkgdir"/usr/share/bash-completion/completions/stgit
	install -Dm0644 completion/stgit.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_stgit
	install -Dm0644 completion/stg.fish \
		"$pkgdir"/usr/share/fish/completions/stg.fish

	# lisp
	install -Dm0644 contrib/stgit.el -t "$pkgdir"/usr/share/emacs/site-lisp

	# vim
	install -Dm0644 contrib/vim/ftdetect/stg.vim -t \
		"$pkgdir"/usr/share/vim/vimfiles/ftdetect
	for vimsyntax in contrib/vim/syntax/*.vim; do
		install -Dm0644 "$vimsyntax" -t "$pkgdir"/usr/share/vim/vimfiles/syntax
	done
}

_emacs() {
	pkgdesc="stg plugin for emacs"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"
	amove usr/share/emacs
}

_vim() {
	pkgdesc="vim filetype and syntax for stgit files"
	install_if="$pkgname=$pkgver-r$pkgrel vim"
	amove usr/share/vim/vimfiles
}

sha512sums="
3352837aabb83276e7d110fa6a7298a0c9e4e2c325771c7e32c1c3c6dfb7a763d10648858b78129e9365f7bddd33ac1cb28df33a74b6b43564c66f653a59da2c  stgit-1.3.tar.gz
"
